﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BlueCMS.Core.Data;
using BlueCMS.Core.Data.Query.Clauses;
using BlueCMS.Core.Data.Query.Columns;
using BlueCMS.Core.Data.Query.Conditions;
using BlueCMS.Core.Data.Query.Tables;
using BlueCMS.Core.Providers;

namespace BlueCMS.Core.Data.Query.Generator
{
	public abstract partial class QueryGeneratorBase
	{
        public virtual string ProcessUnionQuery(UnionClause union, OrderByClause orderBy)
        {
            StringBuilder sb = new StringBuilder();

            GenerateUnionStatement(union, sb);
            GenerateOrderByStatement(orderBy, sb);

            return sb.ToString();
        }

        protected virtual void GenerateUnionStatement(UnionClause union, StringBuilder sb)
        {
            foreach (SelectQuery query in union.Queries)
            {
                sb.Append(query.Sql);
                sb.Append(" UNION ");
            }
            sb.Remove(sb.Length - 7, 7);
        }
	}
}
